{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import cv2\n",
    "import os\n",
    "\n",
    "class Position(object):\n",
    "    def __init__(self, x=0, y=0, extra={}):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "        self.extra = extra\n",
    "    \n",
    "class Rectangle(object):\n",
    "    def __init__(self, left=0, top=0, right=None, bottom=None, width='100%', height='100%'):\n",
    "        pass\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class FileNotExistsException(Exception):\n",
    "    pass\n",
    "\n",
    "class ImageFormatException(Exception):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "class Image(object):\n",
    "    def __init__(self, filename=None, data=None, format=None, cvobj=None):\n",
    "        self._cvobj = None\n",
    "        if filename is not None:\n",
    "            if not os.path.exists(filename):\n",
    "                raise FileNotExistsException('filename: \"%s\"' % filename)\n",
    "            \n",
    "            self._cvobj = cv2.imread(filename)\n",
    "            \n",
    "        if self._cvobj is None:\n",
    "            raise ImageFormatException(\"Canot recognize image format\")\n",
    "    \n",
    "    def show(self):\n",
    "        pass\n",
    "    \n",
    "    def save(self, filename):\n",
    "        pass\n",
    "    \n",
    "    def rect(self):\n",
    "        return Rectangle()\n",
    "    \n",
    "    def crop(self, rect):\n",
    "        return Image(cvobj=self._cvobj)\n",
    "    \n",
    "    \n",
    "#Image(filename='oo')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
